package com.gewu.pm.ui.adapter.approval;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.gewu.pm.R;
import com.gewu.pm.app.AppAdapter;
import com.gewu.pm.bean.ApprovalApplicationBean;

/**
 * 审批申请列表适配器
 */
public class ApprovalApplicationAdapter extends AppAdapter<ApprovalApplicationBean> {

    public ApprovalApplicationAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ItemViewHolder();
    }

    private final class ItemViewHolder extends AppAdapter<?>.ViewHolder {

        private final TextView mTitleView;
        private final TextView mStatusView;
        private final TextView mActivityNameView;
        private final TextView mOrderDateView;
        private final TextView mMainProductScopeView;
        private final TextView mGiftScopeView;
        private final TextView mCustomerScopeView;

        private ItemViewHolder() {
            super(R.layout.approval_application_item);
            mTitleView = findViewById(R.id.tv_title);
            mStatusView = findViewById(R.id.tv_status);
            mActivityNameView = findViewById(R.id.tv_activity_name);
            mOrderDateView = findViewById(R.id.tv_order_date);
            mMainProductScopeView = findViewById(R.id.tv_main_product_scope);
            mGiftScopeView = findViewById(R.id.tv_gift_scope);
            mCustomerScopeView = findViewById(R.id.tv_customer_scope);
        }

        @Override
        public void onBindView(int position) {
            ApprovalApplicationBean item = getItem(position);
            
            mTitleView.setText(item.getTitle());
            mActivityNameView.setText(item.getActivityName());
            mOrderDateView.setText("2022。2.22");
            mMainProductScopeView.setText("指定商品（买赠）/全部商品（满赠）");
            mGiftScopeView.setText("指定商品");
            mCustomerScopeView.setText("部分终端/配送商/销售区域");
            
            // 设置状态标签
            mStatusView.setText(item.getStatusText());
            
            // 根据状态类型设置不同的背景和文字颜色
            switch (item.getType()) {
                case 1: // 待审批
                    mStatusView.setBackgroundResource(R.drawable.shape_red_2_kong);
                    mStatusView.setTextColor(getColor(R.color.red_app));
                    break;
                case 2: // 已通过
                    mStatusView.setBackgroundResource(R.drawable.shape_green_2_kong);
                    mStatusView.setTextColor(getColor(R.color.green_label));
                    break;
                case 3: // 已驳回
                    mStatusView.setBackgroundResource(R.drawable.shape_grey_2_kong);
                    mStatusView.setTextColor(getColor(R.color.cb9));
                    break;
                case 4: // 已撤销
                    mStatusView.setBackgroundResource(R.drawable.shape_grey_2_kong);
                    mStatusView.setTextColor(getColor(R.color.cb9));
                    break;
            }
        }
    }
}

